<template>
	<view class="login-page">
		<view class="logo-section">
			<image class="logo" src="/static/assets/login-logo.png" mode="widthFix"></image>
			<text class="app-name">衣梦空间</text>
		</view>

		<view class="login-form">
			<input class="input" v-model="user.email" type="email" placeholder="请输入邮箱" />
			<input class="input" v-model="user.password" type="password" placeholder="密码" />
			<view class="register-link">
				<text>没有账号？</text>
				<text class="link">
					<navigator url="/pages/register/register">点击注册</navigator>
				</text>
			</view>
		</view>

		<view class="quick-login">
			<text>暂且不登录</text>
			<text style="margin-left: 10rpx;" class="link" @click="jumpHomeFn">返回首页</text>
		</view>

		<button class="login-button" @click="loginFn">登录</button>
	</view>
</template>

<script>
	import api from '../../api'
	export default {
		data() {
			return {
				user: {
					email: "",
					password: "",
				}
			}
		},
		methods: {
			async loginFn() {
				let {
					email,
					password
				} = this.user;
				if (email && password) {
					api.login({
							email,
							password
						})
						.then(
							content => {
								// console.log(content);
								let {
									code,
									msg,
									nickName,
									token
								} = content;
								uni.setStorageSync("AUTOTOKEN", token);
								uni.setStorageSync("NICKNAME", nickName);
								if (code == 200) {
									uni.showToast({
										title: msg,
										icon: 'success'
									})
									setTimeout(() => {
										uni.switchTab({
											url: '/pages/my/my'
										})
									}, 300)
								} else {
									uni.showToast({
										title: msg,
										icon: 'error'
									})
								}
							}
						)
				} else {
					uni.showToast({
						title: "输入框不能为空",
						icon: "none"
					})
				}
			},

			jumpHomeFn() {
				setTimeout(()=>{
					uni.switchTab({
						url: '/pages/index/index'
					})
				},1000)
			}
		}
	}
</script>

<style lang="scss" scoped>
	@improt "../uni.scss";

	.login-page {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 100vh;
		background-color: #f8f8f8;
	}

	.logo-section {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 20px;
	}

	.logo {
		width: 100px;
		height: 100px;
	}

	.app-name {
		font-size: 24px;
		color: #ff6a6a;
		margin-top: 10px;
	}

	.login-form {
		width: 80%;
		background-color: #ffffff;
		padding: 20px;
		border-radius: 10px;
		box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
		margin-bottom: 20px;
	}

	.input {
		width: 100%;
		padding: 10px;
		margin-bottom: 10px;
		border: none;
		border-bottom: 1px solid #ddd;
		font-size: 16px;
	}

	.register-link {
		display: flex;
		justify-content: flex-end;
		margin-top: 20px;
		color: #888;
	}

	.link {
		color: #ff6a6a;
		text-decoration: underline;
	}

	.quick-login {
		margin: 5px 0 100rpx 0;
		color: #888;
	}

	.login-button {
		width: 80%;
		height: 100rpx;
		background: $bgBottom;
		color: #ffffff;
		border: none;
		border-radius: 25px;
		font-size: 18px;
		text-align: center;
		box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
	}
</style>